<?

$thisMdl        = "SLS-ORDER";

$entryBoxStyle  = " style='width:110;height:40;   
                    font-size:100%;  
                    font-weight:bold;' ";

//check if the user has the entry priv
if($UID->getPrivs( $thisMdl, "ENTRY_RIGHTS") > 0){
	
	//check entry
	$bodyPart	=	"<tr>\n".
							"  <td> ".formInputButton("<font size='5'>Entry</font>", // The label
							                          "entry",                       // var Name
							                          "entry",                       // var value
							                          $entryBoxStyle)." </td>\n";    // var properties
}else{
	
	$bodyPart	=	"<tr>\n";
}

$optPrivs = "";
if($UID->getPrivs( $thisMdl, "VIEW_RIGHTS") > 0){
	
	$optPrivs .=	"  <td> ".formInputButton("<font size='5'>View</font>", // The label
  							                          "view",                       // var Name
  							                          "View",                       // var value
  							                          $entryBoxStyle)." </td>\n";   // var properties
}
if($UID->getPrivs( $thisMdl, "EDIT_RIGHTS") > 0){
	
	$optPrivs .=	"  <td> ".formInputButton("<font size='5'>Modify</font>", // The label
  							                          "modify",                       // var Name
  							                          "Modify",                       // var value
  							                          $entryBoxStyle)." </td>\n";     // var properties 
}
if($UID->getPrivs( $thisMdl, "APPROVED_RIGHTS") > 0){

	$optPrivs	.=	"  <td> ".formInputButton("<font size='5'>Approve</font>", // The label
  							                          "approve",                       // var Name
  							                          "Approve",                       // var value
  							                          $entryBoxStyle)." </td>\n";      // var properties
}
if($UID->getPrivs( $thisMdl, "DELETE_RIGHTS") > 0){

	$optPrivs	.=	"  <td> ".formInputButton("<font size='5'>Cancel</font>", // The label
  							                          "cancel",                       // var Name
  							                          "Cancel",                       // var value
  							                          $entryBoxStyle)." </td>\n";     // var properties
}
if($UID->getPrivs( $thisMdl, "DELETE_RIGHTS") > 0){			
	
	$optPrivs	.=	"  <td> ".formInputButton("<font size='5'>Delete</font>", // The label
  							                          "delete",                       // var Name
  							                          "Delete",                       // var value
  							                          $entryBoxStyle)." </td>\n";     // var properties
}


if($_POST["range_period1"]){
 	
 	  $condt  = " AND TR_DATE >= TO_DATE('" .$_POST["range_period1"]. " ','dd-mm-yyyy') ".
 	          " and TR_DATE <= to_date('" .$_POST["range_period2"]. "','dd-mm-yyyy')";
}else{
 
 	$condt  = " AND TR_DATE>=TO_DATE('01-".$_SESSION["sysPeriode"]. "','DD-MM-YYYY') ".
 	          " and TR_DATE<=TO_DATE('".date("d-m-Y")."','DD-MM-YYYY')";
}

//check if criteria is null then default is by entried
//process criteria
switch($_POST["criterialist"]){
	
	case "pending":
		$partCriteria = "WHERE  STATUS='"._NOT_ACTIVE."' ";
		//echo $query;
		$sts[1]  = "selected";
		
		break;
	case "approved":
		$partCriteria = "WHERE  STATUS='"._ACTIVE."' ";
		$sts[2]  = "selected";
		
		break;
	case "canceled":
		$partCriteria = "WHERE  STATUS='"._CANCELED."' ";
		$sts[3]  = "selected";
		
		break;
	default:
		$partCriteria = "WHERE  STATUS<>'"._MONTHLY_UPDATE."' ";
		//echo $query;
		$sts[0]  = "selected";
}

//lets init the first table
echo  "<link rel=\"stylesheet\" type=\"text/css\" href=\"myMenu.css\"/>\n".
			"<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"misc.js\"></SCRIPT> \n".
			"<br/><br/><br/><br/><br/>\n".
			"<form action=# name='crtList' method=post>\n".
			"<table border='1'>\n".
			"<tr>\n".
			" <td>Range period1</td><td><input type='text' id='range1' name='range_period1' value='" .$_POST["range_period1"]. "' maxlength='10' align='left' style='width:100%; height:100%'></td>\n".
			" <td>Range period2</td><td><input type='text' id='range2' name='range_period2' value='" .$_POST["range_period2"]. "' maxlength='10' align='left' style='width:100%; height:100%'></td>\n".
			" <td><select name='criterialist' align='left' onchange='this.form.submit()' >".
  		"  <option value=''	$sts[0]> </option>".
  		"  <option value='pending'  $sts[1]>By Pending</option>".
  		"  <option value='approved' $sts[2]>By Approved</option>".
  		"  <option value='canceled' $sts[3]>By Canceled</option>".
  		" </select></td>".
			" <td colspan='2'><input type='submit' name='criteria' 	value='Criteria'  align='left' style='width:100%; height:100%'></td></tr>\n".
			"<tr>\n".
			"  <input      type='hidden' name='view' 	value='View'>\n".
			"  <input      type='hidden' name='radioview' 	value='".$_POST["radioview"]."'>\n".
			"</form>\n \n".
			"</tr>\n".
			"</table>\n".
			"<table border='1'>\n".
			"<form action=tocmenu_51/viewdboredit.php method=post>\n".
			$bodyPart.
			$optPrivs.
			"</td>\n".
			"</tr>\n".
			"</table>\n";
						
//connect to db to retrieve data with system period as the range
$COracle = new oracleDb;
$COracle->init($_SESSION["ORCL"], 
               $_SESSION["OPASS"],
               $_SESSION["SID"],
               _NO_COMMENT);

$isDbg  = _IS_SILENT;

if ($COracle->connect()) {
	
	$srcDbHdr = "SLS_ORDER_HDR";
	
	fetchLstTransaction($COracle,
	                    $partCriteria . $condt,
	                    $srcDbHdr,
	                    $nrows,
	                    $res);
	
	echo  "<div id='outputPane'>\n".
	      "<table border='1' class='dedeq'>\n".
				"<th align='center'>View/ <br/> Mod </th>\n".
				"<th align='center'>Appr/ <br/> Ccl/ <br/> Del </th>\n".
				"<th align='center'>DATE </th>\n".
				"<th align='center'>REF </th>\n".
				"<th align='center'>STATUS </th>\n".
				"<th align='center'>CUSTOMER </th>\n".
				"<th align='center'>JID </th>\n";
	
	for ($i = 0; $i < $nrows; $i++) {
    
    $stdPropRow = jsOnMouseOver("chgStyle(\"$i\",\"sBlue\");") .
                  jsOnMouseOut ("chgStyle(\"$i\",\"sWhite\");");
                  
    $JID  = $res["JOB_ID"][$i];
            
    switch($res["STATUS"][$i]){
      
      case _NOT_ACTIVE:
        
        $stsType = "PENDING";
        break;
        
      case _ACTIVE:
        
        $stsType = "APPROVED";
        break;
        
      case _CANCELED:
        
        $stsType = "CANCELED";
        break;
        
      default:
        $stsType = "ERROR!!!";
    }
    
    /**
    * if isNormal !=  true then 
    * YES: we dont have any
    *      special handling
    * No : dont print the chkBox
    *
    */
    if($_GET["transVariable"] != 1){
    
      $chkBoxAdd = "<td align='center'> ".formCheckBox("selbox[]",
                                                       $JID,
                                                       $stdProperties)." </td>\n";
    }else{
      
      $chkBoxAdd = "<td align='center'> </td>";
    }
    
    echo  "<tr id='$i' ".$stdPropRow.">\n".
         	"<td align='center'> <input type='radio' name='radioview' value='".$JID."' ></td>\n".
         	$chkBoxAdd.
         	"<td align='center'> ".date("d-m-Y",strtotime($res["TR_DATE"][$i]))."</td>\n".
    			"<td align='center'> ".$res["REFERENCE"][$i]."</td>\n".
    			"<td align='center'> ".$stsType." </td>\n".
    			"<td align='center'> ".$res["CUSTOMER"][$i]." </td>\n".
    			"<td align='center'> ".$res["JOB_ID"][$i]." </td>\n".
          "</tr>\n";
		
	}		
	
	if( $_GET["transVariable"]  != true ||
      $_POST["transVariable"] != true){
	
  	echo  formHidden("transVariable",
                     true,
                     $propNull);
  }
                   
	echo  "</table>\n".
				"<br/>\n".
				"</form>\n".
				"</div>\n"; 
				
	$COracle->dc();
}else{
  
  usrDie("DB connection failed");
}

session_commit();

?>